<template>
  <el-dialog 
    title="角色管理"  
    :visible="isShowRole" 
    append-to-body
    @close="hClose"
    >
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <el-row>
      <el-button type="primary" size="small" @click="hSave">确定</el-button>
      <el-button type="primary" size="small" @click="hClose">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { getEnabledList, assignRole } from '@/api/role'
import { getEmployeeDetail } from '@/api/employee'
export default {
  props: {
    isShowRole: {
      type: Boolean,
      required: true,
    },
    curId: {
      type: Number,
      required: true,
    }
  },
  data () {
    return {
      roleList: [],
      roleIds: []
    }
  },
  async created () {
    const res = await getEnabledList()
    console.log(res)
    this.roleList = res.data
  },
  methods: {
    hClose() {
      this.$emit('update:isShowRole', false)
    },
    async getRoleCur() {
      const res = await getEmployeeDetail(this.curId)
      console.log(res)
      this.roleIds = res.data.roleIds
    },
    async hSave() {
      await assignRole({ id: this.curId, roleIds: this.roleIds })
      this.$message.success('修改权限成功')
      this.hClose()
    }
  }
}
</script>

<style>

</style>